BEGIN {
	print "UPDATE devices SET sync=0 WHERE name='" refNodeName "';";
}

{
	if ($2 == refNodeName) {
		syncTime = $1;
		syncNodeName = $3;
		inSync = $5;
		if (inSync==0) {
			print "UPDATE devices SET sync=" syncTime " WHERE name='" syncNodeName "';";
			print "UPDATE events SET time=logTime+" syncTime " WHERE device='" syncNodeName "';";
			print "UPDATE resources SET time=logTime+" syncTime " WHERE device='" syncNodeName "';";
		}
	} else if ($3 == refNodeName) {
		syncTime = -$1;
		syncNodeName = $2;
		inSync = $4;
		if (inSync==0) {
			print "UPDATE devices SET sync=" syncTime " WHERE name='" syncNodeName "';";
			print "UPDATE events SET time=logTime+" syncTime " WHERE device='" syncNodeName "';";
			print "UPDATE resources SET time=logTime+" syncTime " WHERE device='" syncNodeName "';";
		}
	}
}

END {
}
